

package WordHandling;


import java.io.File;
import java.util.*;

/**
 *
 * @author Farcus
 */
public class Ranker {
	public int rank;
	public Index[] names;
	Tokenizer toke = new Tokenizer();
	public class Index{
		private String filename = null;
		private int docNum = 0;
		private int wordNum = 0;
		private int docRank =0;
		int getDocNum(){
			return docNum;
		}
		int getWordNum(){
			return wordNum;
		}
		int getDocRank(){
			return docRank;
		}
		String getFilename(){
			return filename;
		}
	}
	
	int[] words = new int[100];
	public int setDocSize(ArrayList<String> a){
		int testsize = a.size();
		return testsize;
	}
	public int docsizeGetter(int doc){
		List<List<String>> work = toke.getFiles();
		int docsize = work.get(doc).size();
		return docsize;
	}
	public int docnumGetter(){
		List<List<String>> work = toke.getFiles();
		int docnums = work.size();
		return docnums;
	}
	public int querySizeGetter(){
		int qSize= toke.getQueryStrings().size();
		return qSize;
	}
	public int[] calculator(){
		int[] ranks = new int[getFileNamesBeta().length];
		for(int ii = 0; ii<ranks.length; ii++){
			ranks[ii]=0;
		}
		for(int i =0; i < getFileNamesBeta().length; i++){
			for(int j = 0; j < docsizeGetter(j); j++){
				for(int k = 0; k < querySizeGetter(); k++){
					if(toke.getQueryStrings().get(k)==
						toke.getFiles().get(i).get(j))
						ranks[i]+=1;
				}
			}
			//for each unique query hit in a doc, return the wordNum and put in list
			//after list is populated compare the distances of the wordNums.
			//add the total distance to rank
		
		}
		return ranks;
		
	}
	public int[] arrayMaker(){
		for(int i = 0; i < docnumGetter(); i++){
			words[i]=docsizeGetter(i);
		}
		return words;
	}
	
	public String[] getFileNamesBeta(){
	ArrayList<File> files = toke.getDocumentList();
	String[] names = new String[files.size()];
	for(int i = 0; i < files.size(); i ++){
		names[i]=files.get(i).toString();
	}
	
	return names;
	}
	public Index[] indexBuilder(){
		
		Index[] Indexed = new Index[toke.getDocumentList().size()];
		int[] docRankArray = calculator();
		int[] wordsArray = arrayMaker();
		String[] namesArray = getFileNamesBeta();
		for(int i = 0; i < Indexed.length; i++){
			Indexed[i].docRank = docRankArray[i];
			Indexed[i].filename = namesArray[i];
			Indexed[i].wordNum = wordsArray[i];
			Indexed[i].docNum =i;
		}
		return Indexed;
	}
	
}
